/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de La Frontera
 * License Type: Academic
 */
package orm.tallerdesoa.impl;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;
import orm.tallerdesoa.*;

public class Tcp_personaDAOImpl implements orm.tallerdesoa.dao.Tcp_personaDAO {
	public Tcp_persona loadTcp_personaByORMID(int pers_id) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_personaByORMID(session, pers_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona getTcp_personaByORMID(int pers_id) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return getTcp_personaByORMID(session, pers_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByORMID(int pers_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_personaByORMID(session, pers_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona getTcp_personaByORMID(int pers_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return getTcp_personaByORMID(session, pers_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByORMID(PersistentSession session, int pers_id) throws PersistentException {
		try {
			return (Tcp_persona) session.load(orm.tallerdesoa.Tcp_persona.class, new Integer(pers_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona getTcp_personaByORMID(PersistentSession session, int pers_id) throws PersistentException {
		try {
			return (Tcp_persona) session.get(orm.tallerdesoa.Tcp_persona.class, new Integer(pers_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByORMID(PersistentSession session, int pers_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tcp_persona) session.load(orm.tallerdesoa.Tcp_persona.class, new Integer(pers_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona getTcp_personaByORMID(PersistentSession session, int pers_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tcp_persona) session.get(orm.tallerdesoa.Tcp_persona.class, new Integer(pers_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_persona(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return queryTcp_persona(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_persona(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return queryTcp_persona(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona[] listTcp_personaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return listTcp_personaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona[] listTcp_personaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return listTcp_personaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_persona(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_persona as Tcp_persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_persona(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_persona as Tcp_persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Tcp_persona", lockMode);
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona[] listTcp_personaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		try {
			List list = queryTcp_persona(session, condition, orderBy);
			return (Tcp_persona[]) list.toArray(new Tcp_persona[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona[] listTcp_personaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryTcp_persona(session, condition, orderBy, lockMode);
			return (Tcp_persona[]) list.toArray(new Tcp_persona[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_personaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_personaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tcp_persona[] tcp_personas = listTcp_personaByQuery(session, condition, orderBy);
		if (tcp_personas != null && tcp_personas.length > 0)
			return tcp_personas[0];
		else
			return null;
	}
	
	public Tcp_persona loadTcp_personaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tcp_persona[] tcp_personas = listTcp_personaByQuery(session, condition, orderBy, lockMode);
		if (tcp_personas != null && tcp_personas.length > 0)
			return tcp_personas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTcp_personaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return iterateTcp_personaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTcp_personaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return iterateTcp_personaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTcp_personaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_persona as Tcp_persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTcp_personaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_persona as Tcp_persona");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Tcp_persona", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona createTcp_persona() {
		return new orm.tallerdesoa.Tcp_persona();
	}
	
	public boolean save(orm.tallerdesoa.Tcp_persona tcp_persona) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().saveObject(tcp_persona);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.tallerdesoa.Tcp_persona tcp_persona) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().deleteObject(tcp_persona);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.tallerdesoa.Tcp_persona tcp_persona)throws PersistentException {
		try {
			orm.tallerdesoa.Tcp_publicacion[] lTcp_publicacions = tcp_persona.tcp_publicacion.toArray();
			for(int i = 0; i < lTcp_publicacions.length; i++) {
				lTcp_publicacions[i].setTcp_personaPers(null);
			}
			return delete(tcp_persona);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.tallerdesoa.Tcp_persona tcp_persona, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.tallerdesoa.Tcp_publicacion[] lTcp_publicacions = tcp_persona.tcp_publicacion.toArray();
			for(int i = 0; i < lTcp_publicacions.length; i++) {
				lTcp_publicacions[i].setTcp_personaPers(null);
			}
			try {
				session.delete(tcp_persona);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.tallerdesoa.Tcp_persona tcp_persona) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession().refresh(tcp_persona);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.tallerdesoa.Tcp_persona tcp_persona) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession().evict(tcp_persona);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_persona loadTcp_personaByCriteria(Tcp_personaCriteria tcp_personaCriteria) {
		Tcp_persona[] tcp_personas = listTcp_personaByCriteria(tcp_personaCriteria);
		if(tcp_personas == null || tcp_personas.length == 0) {
			return null;
		}
		return tcp_personas[0];
	}
	
	public Tcp_persona[] listTcp_personaByCriteria(Tcp_personaCriteria tcp_personaCriteria) {
		return tcp_personaCriteria.listTcp_persona();
	}
}
